# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ruby-charlock_holmes
_gemname=charlock_holmes
pkgver=0.7.7
pkgrel=15
pkgdesc="Character encoding detection, brought to you by ICU"
url="https://github.com/brianmario/charlock_holmes"
arch="all"
license="MIT"
checkdepends="ruby-minitest ruby-rake"
makedepends="icu-dev ruby ruby-dev zlib-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/brianmario/$_gemname/archive/v$pkgver.tar.gz
	gemspec.patch
	rakefile.patch
	tests-no-bundler.patch
	fix-minitest-compat.patch
	"
builddir="$srcdir/$_gemname-$pkgver"

build() {
	gem build $_gemname.gemspec

	gem install --local \
		--install-dir dist \
		--ignore-dependencies \
		--no-document \
		--verbose \
		$_gemname

	# Needed for tests.
	cp -l dist/extensions/*/*/$_gemname-*/$_gemname/*.so lib/$_gemname/
}

check() {
	rake test
}

package() {
	local gemdir="$pkgdir/$(ruby -e 'puts Gem.default_dir')"
	cd "$builddir"/dist

	mkdir -p "$gemdir"
	cp -r extensions gems specifications "$gemdir"/

	# Remove unnecessary and duplicated files.
	rm -f "$gemdir"/extensions/*/*/$_gemname-*/mkmf.log
	cd "$gemdir"/gems/$_gemname-$pkgver
	rm -rf ext/ lib/$_gemname/*.so
}

sha512sums="
5950db982fbbcf41c6c8f893b2d5e1d755ec85e55bd6ce9072507c06925251edb3198840fdf346e8b74f06f4dc1d63bf94657ce582b78947751d20980f71aa8e  ruby-charlock_holmes-0.7.7.tar.gz
c30ca2b7ac859bae553f633ed1df1947ad735c804f0edacd20c50d2d38d277d4a5a883459134a8caf832230754f272ec2a55e42e1cdf24eea1954aad9ead2679  gemspec.patch
ac59baaa1f17281f9b07c035b367e697e08943f4e0cf2b5a718e7a957c1c156bbea0c240646cdea94575e7729e60415ee6293edbaa7b86aad3285282b9385181  rakefile.patch
6fcdc90539154a007109a4958d7fc7451b0d5a69840866af928ce7233823b32a0f5a8d7d3d9b249978807ff8dced1a1f85d14187c99b7fff1f2497e26b11a120  tests-no-bundler.patch
7ab90dca57113c14f61a65a29176373c7a00d014a47f5cc2dccdcbc076a9639ed4895f405ea7d869b7788a04f8cf336fa41882e6eb231dd65550fdf4746632a4  fix-minitest-compat.patch
"
